package jdwl.hrmgrsys.action;

import java.util.Date;
import java.util.LinkedHashMap;

import javax.annotation.Resource;

import jdwl.hrmgrsys.pojo.Staff;
import jdwl.hrmgrsys.service.StaffMgrService;

import net.sf.json.JSONObject;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ssh.core.QueryResult;

@Controller("staffAction")
@Scope("prototype")
public class StaffAction extends PageAction<Staff> {
	@Resource(name = "staff")
	private Staff staff;
	@Resource(name = "staffService")
	private StaffMgrService service;

	public Staff getStaff() {
		return staff;
	}

	public void setStaff(Staff staff) {
		this.staff = staff;
	}

	public StaffMgrService getService() {
		return service;
	}

	public void setService(StaffMgrService service) {
		this.service = service;
	}
	
	public QueryResult<Staff> getStaffs() {
		return getResult();
	}

	public void setStaffs(QueryResult<Staff> staffs) {
		this.setResult(staffs);
	}

	/**
	 * 增加员工
	 * 
	 * @param staff
	 * @return
	 */
	public String addStaff() {
		staff.setCreateDate(new Date());
		staff.setCreateTime(new Date());
		staff.setUpdateDate(new Date());
		staff.setUpdateTime(new Date());
		getService().save(staff);
		return SUCCESS;
	}

	public String listStaff() {
		LinkedHashMap orderBy = getOrderBy();
		orderBy.put("update", "desc");
		setStaffs(getService().listStaff(getPageNo(),getiDisplayLength(), null,
				orderBy));
		return SUCCESS;
	}

}
